package com.my.zl.console.service.select.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.my.zl.console.dao.autocode.ZlDictDtlMapper;
import com.my.zl.console.dao.autocode.ZlDictMapper;
import com.my.zl.console.dao.autocode.ZlFieldMappingDtlMapper;
import com.my.zl.console.dao.autocode.ZlFieldMappingMapper;
import com.my.zl.console.dao.autocode.ZlKeywordDtlMapper;
import com.my.zl.console.dao.autocode.ZlKeywordMapper;
import com.my.zl.console.dao.autocode.ZlProjectMapper;
import com.my.zl.console.dao.autocode.ZlProjectModuleMapper;
import com.my.zl.console.dao.autocode.ZlTableColumnMapper;
import com.my.zl.console.dao.autocode.ZlTableMapper;
import com.my.zl.console.dao.autocode.ZlTemplateDtlMapper;
import com.my.zl.console.dao.autocode.ZlTemplateMapper;
import com.my.zl.console.dao.autocode.ZlValidationMapper;
import com.my.zl.console.dao.autocode.ZlWebComponentMapper;
import com.my.zl.console.entity.autocode.ZlDict;
import com.my.zl.console.entity.autocode.ZlDictDtl;
import com.my.zl.console.entity.autocode.ZlFieldMapping;
import com.my.zl.console.entity.autocode.ZlKeyword;
import com.my.zl.console.entity.autocode.ZlProject;
import com.my.zl.console.entity.autocode.ZlProjectModule;
import com.my.zl.console.entity.autocode.ZlTable;
import com.my.zl.console.entity.autocode.ZlTableColumn;
import com.my.zl.console.entity.autocode.ZlTemplate;
import com.my.zl.console.entity.autocode.ZlTemplateDtl;
import com.my.zl.console.entity.autocode.ZlValidation;
import com.my.zl.console.entity.autocode.ZlWebComponent;
import com.my.zl.console.service.base.BaseManager;
import com.my.zl.console.service.select.ISelectService;

import org.apache.commons.lang.StringUtils;

/**
 *  最终配置记录
 * @author ZL
 */
@Service
public class SelectServiceImpl extends BaseManager implements ISelectService {

    @Autowired
    private ZlDictMapper dictMapper;
    @Autowired
    private ZlDictDtlMapper dictDtlMapper;
    @Autowired
    private ZlFieldMappingMapper fieldMappingMapper;
    @Autowired
    private ZlFieldMappingDtlMapper fieldMappingDtlMapper;
    @Autowired
    private ZlKeywordMapper keywordMapper;
    @Autowired
    private ZlKeywordDtlMapper keywordDtlMapper;
    @Autowired
    private ZlProjectMapper projectMapper;
    @Autowired
    private ZlProjectModuleMapper projectModuleMapper;
    @Autowired
    private ZlValidationMapper validationMapper;
    @Autowired
    private ZlTableMapper tableMapper;
    @Autowired
    private ZlTableColumnMapper tableColumnMapper;
    @Autowired
    private ZlTemplateMapper templateMapper;
    @Autowired
    private ZlTemplateDtlMapper templateDtlMapper;
    @Autowired
    private ZlWebComponentMapper webComponentMapper;
    
    @Override
    public List<ZlDict> queryDictForSelect() throws Exception {
        // TODO Auto-generated method stub
        Map<String,Object> param = new HashMap<>();
        param.put("dataStatus", "00");
        return dictMapper.selectListByMapForSelectItem(param);
    }
    
    @Override
    public List<ZlDictDtl> queryDictDtlForSelect(String dictType) {
        // TODO Auto-generated method stub
        List<ZlDictDtl> listAll = new ArrayList<>();
        Map<String,Object> param = new HashMap<>();
        param.put("dataStatus", "00");
        if(StringUtils.isNotBlank(dictType)){
          String[] types = dictType.split(",");
          for(String x : types){
              param.put("dictType", x);
              List<ZlDictDtl> list = dictDtlMapper.selectListByMapForSelectItem(param);
              if(list != null ){
                  listAll.addAll(list);
              }
          }
        }else{
            listAll = dictDtlMapper.selectListByMapForSelectItem(param);
        }
        return listAll;
    }
    
    @Override
    public List<ZlProject> queryProjectForSelect() throws Exception {
        // TODO Auto-generated method stub
        Map<String,Object> param = new HashMap<>();
        param.put("dataStatus", "00");
        return projectMapper.selectListByMapForSelectItem(param);
    }

    @Override
    public List<ZlProjectModule> queryProjectModuleForSelect(String projectId) {
        // TODO Auto-generated method stub
        Map<String,Object> param = new HashMap<>();
        param.put("projectId", projectId);
        param.put("dataStatus", "00");
        return projectModuleMapper.selectListByMapForSelectItem(param);
    }

    @Override
    public List<ZlTable> queryTableForSelect(String projectId) {
        // TODO Auto-generated method stub
        Map<String,Object> param = new HashMap<>();
        param.put("projectId", projectId);
        param.put("dataStatus", "00");
        return tableMapper.selectListByMapForSelectItem(param);
    }
    
    @Override
    public List<ZlTableColumn> queryTableColumnForSelect(String tableCode) {
        // TODO Auto-generated method stub
        Map<String,Object> param = new HashMap<>();
        param.put("tableCode", tableCode);
        param.put("dataStatus", "00");
        return tableColumnMapper.selectListByMapForSelectItem(param);
    }

    @Override
    public List<ZlTemplate> queryTemplateForSelect(String moduleId) {
        // TODO Auto-generated method stub
        Map<String,Object> param = new HashMap<>();
        param.put("moduleId", moduleId);
        param.put("dataStatus", "00");
        return templateMapper.selectListByMapForSelectItem(param);
    }

    @Override
    public List<ZlTemplateDtl> queryTemplateDtlForSelect(String templateId) {
        // TODO Auto-generated method stub
        Map<String,Object> param = new HashMap<>();
        param.put("templateId", templateId);
        param.put("dataStatus", "00");
        return templateDtlMapper.selectListByMapForSelectItem(param);
    }

    @Override
    public List<ZlValidation> queryValidationForSelect(String projectId) {
        // TODO Auto-generated method stub
        Map<String,Object> param = new HashMap<>();
        param.put("projectId", projectId);
        param.put("dataStatus", "00");
        return validationMapper.selectListByMap(param);
    }

    @Override
    public List<ZlFieldMapping> queryFieldMappingForSelect() {
        // TODO Auto-generated method stub
        Map<String,Object> param = new HashMap<>();
        param.put("dataStatus", "00");
        return fieldMappingMapper.selectListByMap(param);
    }

    @Override
    public List<ZlKeyword> queryKeywordForSelect() throws Exception {
        // TODO Auto-generated method stub
        Map<String,Object> param = new HashMap<>();
        param.put("dataStatus", "00");
        return keywordMapper.selectListByMap(param);
    }

    @Override
    public List<ZlWebComponent> queryWebComponentForSelect(String projectId) throws Exception {
        // TODO Auto-generated method stub
        Map<String,Object> param = new HashMap<>();
        param.put("projectId", projectId);
        param.put("dataStatus", "00");
        return webComponentMapper.selectListByMap(param);
    }

    @Override
    public ZlTemplate queryTemplate(String templateId) throws Exception {
     // TODO Auto-generated method stub
        Map<String, Object> param = new HashMap<>();
        param.put("templateId", templateId);
        return templateMapper.selectOneByMap(param);
    }
    
    @Override
    public ZlTemplateDtl queryTemplateDtl(String templateFileId) {
        // TODO Auto-generated method stub
        Map<String,Object> param = new HashMap<>();
        param.put("templateFileId", templateFileId);
        return templateDtlMapper.selectOneByMap(param);
    }
    
    @Override
    public ZlProject queryProject(String projectId) throws Exception {
     // TODO Auto-generated method stub
        Map<String, Object> param = new HashMap<>();
        param.put("projectId", projectId);
        return projectMapper.selectOneByMap(param);
    }
    
    

}